package HomeWork1;
/*
 *@Student 张策
 */
public class Main2 {
    public static void main(String[] args) {
        Moeny p1 = new Moeny();
        Thread thread1 = new Thread(p1);
        thread1.setName("一号：");
        Thread thread2 = new Thread(p1);
        thread2.setName("二号：");
        Thread thread3 = new Thread(p1);
        thread3.setName("三号：");
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
class Moeny implements Runnable{
    private int money=10000;
    public void setMoney(int money) {
        this.money = money;
    }
    @Override
    public void run() {
        while (true) {
            synchronized (this){
            if (money <= 0) {
                break;
            }
            money -= 1000;
            System.out.println(Thread.currentThread().getName() + "取出:1000元" + "剩余:" + money);
        }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
